package com.drivingbarefoot.games.OneFour24;

import java.util.HashMap;
import java.util.Iterator;


public class Rules {
	private boolean hasOne = false;

	private boolean hasFour = false;

	private int score = 0;

	private int keptDiceCount = 0;

	public Rules(HashMap<Integer, Die> dice) {
		Die d;
		Iterator<Die> i = dice.values().iterator();
		while (i.hasNext()) {
			d = i.next();

			if (d.isKept()) {
				int val = d.getValue();

				if (val == 1 && !hasOne)
					hasOne = true;
				else if (val == 4 && !hasFour)
					hasFour = true;
				else
					score += val;

				keptDiceCount++;
			}
		}
	}

	public boolean CanUserPlayAgain() {
		return (keptDiceCount < 6);
	}

	public boolean DidUserQualify() {
		return hasOne && hasFour;
	}

	public int GetScore() {
		return score;
	}

	public boolean IsGameOver() {
		return (keptDiceCount == 6);
	}
}
